package util;

import java.util.Scanner;

public class OrderConsole {
	
	private OrderConsole(){}
	
	private static Scanner scanner = new Scanner(System.in);
	
	public static void println(String str) {
		System.out.println(str);
	}
	
	public static void print(String str) {
		System.out.print(str);
	}
	
	public static String askUserInput(String prompt){
		String input = null;
		while (true) {
			System.out.print(prompt+">");
			input = scanner.nextLine();
			if (!input.trim().equals(""))
				break;
		}
		return input;
	}
	
	public static int askUserInputInt(String prompt){
		int result = -1;
		while(true){
			String out = askUserInput(prompt);
			try {
				result = Integer.parseInt(out);
			} catch (Exception e) {
				println("请输入合法的数字");
			}	
			
			if(result != -1){
				break;
			}
		}
		return result;
	}
	
	public static double askUserInputDouble(String prompt){
		double result = 0.0d;
		while(true){
			String out = askUserInput(prompt);
			try {
				result = Double.parseDouble(out);
			} catch (Exception e) {
				println("请输入合法的数字");
			}	
			
			if(result != -1){
				break;
			}
		}
		return result;
	}
	
	public static void exit(){
		System.exit(0);
	}
}
